<template>
<div>
  <el-table :data="tableData" stripe style="width: 100%" v-loading="loading">
    <el-table-column header-align="center" prop="name" align="center" label="影院名称" width="180"></el-table-column>
    <el-table-column header-align="center" prop="cityName" align="center" label="城市" width="180"></el-table-column>
    <el-table-column header-align="center" prop="areaName" align="center" label="地区"></el-table-column>
    <el-table-column header-align="center" prop="lowPrice" align="center" label="最低价格"></el-table-column>
    <el-table-column header-align="center" align="center" label="操作">
      <template slot-scope="scope">
        <!-- <scope.row是本行对应的数据 -->
        <router-link :to="`/cinema/edit/${scope.row.cinemaId}`">
          <el-button type="text" size="small">编辑</el-button>
        </router-link>
        <el-button size="mini" type="danger" @click="handleDelete(scope.$index, scope.row)">删除</el-button>
      </template>
    </el-table-column>
  </el-table>


  <el-row v-if="value">
      <el-pagination
        @current-change="changepage"
        :page-size="pageSize"
        layout="prev, pager, next"
        :total="total"
        class="pagination"
      ></el-pagination>
    </el-row>

  </div>
</template>

<script>
export default {
  data() {
    return {
      value:false,
      loading: false,
      tableData: [],
       pageNum: 1,
      pageSize: 10,
      total: 0,
    };
  },
  created() {
    this.getlist(this.pageNum);
  },
  methods: {
    async getlist(pageNum) {
      let url = "http://132.232.87.95:3000/admin/cinema/getList";
      this.loading = true;
      try {
        let res = await this.axios.post(url,{
            pageSize: this.pageSize,
            pageNum
        });
        this.loading = false;
        this.total = res.data.total;
        this.tableData = res.data.cinemas;
      } catch (error) {
        this.loading = false;
      }
       //分页少于2页时不显示页码
      if(this.total>this.pageSize){
        this.value=true
      }
    },
     async changepage(pageNum) {
      let dete = await this.getlist(pageNum);

      
    },
     //删除
   async handleDelete(index, row) {
      let btn = confirm("是否要删除");
      if (btn == true) {
        
        let url = "/cinema/delById";
        
        let res =await this.$axios.post(url, row);
        this.tableData.splice(index, 1);
        this.$message({
          message: "删除成功"
        });
      } else {
      }
    }
  }
};
</script>